<?php  if(!defined('BASEPATH')) exit('No direct script access allowed');



    Class Staff_model extends CI_Model{

        

        public function __construct(){

            parent::__construct();

            $this->staff= 'staffs';

        }

        

        public function getListStaff($limit=null, $offset=null){

            $this->db->select();
            $this->db->join('departments', 'staffs.iddepartment = departments.iddepartment', 'left');

            if(!empty($offset) && !empty($limit)){
                $this->db->limit($limit,$offset);
            }
            if(empty($offset) && !empty($limit)){
                $this->db->limit($limit);   
            }
            
            $data = $this->db->get($this->staff);

            $data = $data->result_array();

            return $data;

        }

        

        public function addStaff($data){

            $this->db->insert($this->staff,$data);

            $affect = $this->db->affected_rows();

            if($affect){

                return true;

            }else{

                return false;

            }   

        } 

        

        public function updateStaff($data,$condition){

            $this->db->where($condition);

            $this->db->update($this->staff,$data);

            $affect = $this->db->affected_rows();

            if($affect){

                return true;

            }else{

                return false;

            }   

        } 

        

        public function getSingleStaff($condition){

            $data = $this->db->select();

            $this->db->where($condition);

            $data = $data->get($this->staff);

            $data = $data->row_array(); 

            return $data;

        }

        

        public function deleteStaff($condition){

            $this->db->where($condition);

            $this->db->delete($this->staff);

            $affect = $this->db->affected_rows();

            if($affect){

                return true;

            }else{

                return false;

            }   

        }
        
        public function countall(){
            return $this->db->count_all($this->staff);
        }

    }

?>